package cn.imnaer.service.rpc.userinfo.dao;

import cn.imnaer.database.BaseDao;
import cn.imnaer.database.define.DBConstant;
import cn.imnaer.service.persistence.model.User;
import cn.imnaer.service.persistence.model.consts.USER;

public class UserDaoImpl extends BaseDao<User> {
	private static UserDaoImpl instance = new UserDaoImpl();

	private UserDaoImpl() {
		super();
	}

	public static UserDaoImpl getInstance() {
		return instance;
	}

	@Override
	protected String getDbSpaceName() {
		return DBConstant.SPACE.USER_INFO_SPACE;
	}

	@Override
	protected String getDbCollectionName() {
		return DBConstant.COLLECTION.USER_INFO_COLLECTION;
	}

	@Override
	protected String getPrimaryKey() {
		return USER.userId;
	}

	@Override
	protected void beforeSave(User user) {

		if (user.getName() == null || user.getName().isEmpty()) {
			user.setName(user.getUserId());
		}

	}
}
